import request from '@/utils/request'
import {parseStrEmpty} from "@/utils/ruoyi";

// 查询设备列表
export function listDevice(query) {
  return request({
    url: '/device/device/list',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getDevice(deviceId) {
  return request({
    url: '/device/device/' + parseStrEmpty(deviceId),
    method: 'get'
  })
}
// 查询设备详细
export function getDeviceBySn(query) {
  return request({
    url: '/device/device/getInfoBySn',
    method: 'get',
    params: query
  })
}

// 查询设备运行状态
export function checkDeviceStatus(query) {
  return request({
    url: '/device/device/checkStatus',
    method: 'get',
    params: query
  })
}

// 查询设备取电二维码
export function getDeviceQrcode(query) {
  return request({
    url: '/device/device/qrcode',
    method: 'get',
    params: query
  })
}

// 新增设备
export function addDevice(data) {
  return request({
    url: '/device/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(data) {
  return request({
    url: '/device/device',
    method: 'put',
    data: data
  })
}
export function updateDeviceWifi(data) {
  return request({
    url: '/device/device/editWifi',
    method: 'put',
    data: data
  })
}
export function updateDeviceCttime(data) {
  return request({
    url: '/device/device/editCttime',
    method: 'put',
    data: data
  })
}
export function updateDeviceDdtime(data) {
  return request({
    url: '/device/device/editDdtime',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delDevice(deviceId) {
  return request({
    url: '/device/device/' + deviceId,
    method: 'delete'
  })
}

// 电路开关修改
export function changeDeviceCircuitSwitch(productId, deviceId, deviceName, circuitSwitch) {
  const data = {
    productId,
    deviceId,
    deviceName,
    circuitSwitch
  }
  return request({
    url: '/device/device/changeCircuitSwitch',
    method: 'put',
    data: data
  })
}

// 扫码开电修改
export function changeDeviceScanPoweron(productId, deviceId, deviceName, scanPoweron) {
  const data = {
    productId,
    deviceId,
    deviceName,
    scanPoweron
  }
  return request({
    url: '/device/device/changeScanPoweron',
    method: 'put',
    data: data
  })
}

// 人走断电修改
export function changeDeviceLavePoweroff(productId, deviceId, deviceName, leavePoweroff) {
  const data = {
    productId,
    deviceId,
    deviceName,
    leavePoweroff
  }
  return request({
    url: '/device/device/changeLavePoweroff',
    method: 'put',
    data: data
  })
}

// 获取微信签名信息
export function getWxSign(query) {
  return request({
    url: '/weixin/getWxSign',
    method: 'get',
    params: query
  })
}

// 上报固定设备
export function reportFixDevice(query) {
  return request({
    url: '/device/device/reportFixDevice',
    method: 'get',
    params: query
  })
}
// 列出固定设备
export function listFixDevice(query) {
  return request({
    url: '/device/device/listFixDevice',
    method: 'get',
    params: query
  })
}
// 保存固定设备
export function saveFixDevice(deviceName, macs) {
  console.log("deviceName="+deviceName+", macs="+macs)
  const data = {
    deviceName,
    macs
  }
  return request({
    url: '/device/device/saveFixDevice',
    method: 'put',
    data: data
  })
}

// 获取首页数量
export function getIndexCount(query) {
  return request({
    url: '/device/device/getIndexCount',
    method: 'get',
    params: query
  })
}
